package org.piaohao.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;

/**
 * Created on : 2013-5-5, 10:40:27
 *
 * @author piaohao
 */
public class GlobalInterceptor implements Interceptor {

    @Override
    public void intercept(ActionInvocation ai) {
        String methodName = ai.getMethodName();
        String controllerKey = ai.getControllerKey();
        String actionKey = ai.getActionKey();
        if (actionKey.equalsIgnoreCase("/main/login") || actionKey.equalsIgnoreCase("/captcha/get")
                || actionKey.equalsIgnoreCase("/main/dologin") || actionKey.equalsIgnoreCase("/main/logout")) {
            ai.invoke();
        } else {
            Object o = ai.getController().getSessionAttr("user");
            if (o == null) {
                ai.getController().redirect("/resource/403.jsp");
            } else {
                ai.invoke();
            }
        }
    }
}
